/**
 *
 */
package de.cbf.cam.dsa.services.impl.rcp_provider;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.cbf.cam.dsa.rcp.model.entities.ProfessionDSA;
import de.cbf.cam.dsa.services.impl.rcp_provider.extension.interfaces.IRCPPersisterProfession;
import de.cbf.cam.dsa.services.interfaces.rcp_provider.IServiceDSAProviderProfession;
import de.cbf.cam.dsa.services.interfaces.rcp_provider.exceptions.EntityNotFoundException;
import de.cbf.util.db.interfaces.exceptions.EntityLoadException;
import de.cbf.util.db.interfaces.exceptions.EntitySaveException;
import de.cbf.util.uuidheader.entities.UUIDHeader;

/**
 * @author Alti
 *
 */
public class ProviderProfession implements IServiceDSAProviderProfession {
	private static final Log logger = LogFactory.getLog(ProviderProfession.class);
	protected IRCPPersisterProfession persister;

	public ProviderProfession() {
		super();

	}

	@Override
	public UUIDHeader getEntityByItsID(UUID id) throws EntityNotFoundException {
		ProfessionDSA profession;
		try {
			profession = persister.loadProfession(id);
		} catch (EntityLoadException e) {
			throw new EntityNotFoundException("ProfessionDSA NOT found,id: "+id,e);
		}
		return profession;
	}

	public List<ProfessionDSA> provideAllProfessions(){
		List<ProfessionDSA> resultList = new ArrayList<ProfessionDSA>();
		try {
			resultList.addAll(persister.loadAllProfessions());
		} catch (EntityLoadException e) {
			logger.error(e);
		}
		return resultList;
	}

	@Override
	public void persistProfession(ProfessionDSA entity) {
		try {
			persister.saveProfession(entity);
		} catch (EntitySaveException e) {
			logger.error(e);
		}
	}

	@Override
	public String getName() {
		return "Profession provider via "+persister.getName();
	}

	public IRCPPersisterProfession getPersister() {
		return persister;
	}

	public void setPersister(IRCPPersisterProfession persister) {
		this.persister = persister;
	}



}
